*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*
* Diehl/Wolter: ATTITUDES ABOUT CONTAINMENT MEASURES DURING THE
*               2020/2021 CORONAVIRUS PANDEMIC:
*               SELF-INTEREST, OR BROADER POLITICAL ORIENTATIONS?
*
* Do-File for variable preparation of the November wave
*
* This version: 20210430
*
* Author: Felix Wolter, felix.wolter@uni-konstanz.de
*
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*Load November 2020 Kantar survey (data file with Covid rates has some missings to to missing PLZ!)
use "kantarcovidratesnovember.dta", clear
numlabel _all, add

*Drop Softlaunch
tab sample
drop if sample==1

*Wave (time) identifier
gen time = 1
label variable time "Time/wave"
label define time 0 "spring 2020" 1 "november 2020"
label value time time
tab time, mis

*Rename Wave 1 identifier and repair id
drop id
rename id_w1 id
replace id = id_w2 if id==.
replace id = 50000+_n if id==.

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Dependent variable
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
tab1 einst1-einst6, mis

foreach x of varlist einst1-einst6 {
	gen `x'rec = 6-`x'
}
tab1 *rec, mis

rename einst1rec openkitas
rename einst2rec openschools
rename einst3rec openrestau
rename einst4rec opencontact
rename einst5rec openborders
rename einst6rec openevents

factor open* [aweight=gewicht], pcf blanks(.4)
rotate, oblique oblimin blanks(.4)

alpha open*, item detail

*Generate index var of all 6 items
egen openindex = rowmean(open*)
tab openindex, mis
sum openindex [aweight=gewicht]

*z-standardize dependent variable
sum openindex [aweight=gewicht]
center openindex [aweight=gewicht], gen(zopenindex) double nolabel standardize
center openindex , gen(znowopenindex) double nolabel standardize

*5-point-scale var
gen openindex5 = openindex

*Copy five-point scale variable
foreach x of varlist openkitas-openevents {
	gen `x'5 = `x'
}

*z-standardize openkitas and openschools for robustness analysis
center openkitas [aweight=gewicht], gen(zopenkitas) double nolabel standardize
center openschools [aweight=gewicht], gen(zopenschools) double nolabel standardize

*Create opposition dummies for descriptive analysis
foreach x of varlist openkitas5-openevents5 {
    recode `x' (1/3=0) (4 5=1), gen(`x'dum)
}
tab1 *dum, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Independent variables
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Threats
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Sociotropic threat
tab1 masn2a-masn2h, mis
gen double sttwork = masn2a
gen double sttfinance = masn2b
gen double sttfamily = masn2c
gen double sttrights = masn2d

pwcorr stt*, sig
factor stt* [aweight=gewicht], pcf blanks(.4)
alpha stt*, item detail

*Create index variable
egen stt = rowmean(stt*)
tab stt, mis

*Subindizes
egen sttshort = rowmean(sttwork sttfinance sttfamily)
egen sttecon = rowmean(sttwork sttfinance)


*Individual threat
tab1 masn2e-masn2h, mis
gen double idtwork = masn2e
gen double idtfinance = masn2f
gen double idtfamily = masn2g
gen double idtrights = masn2h

pwcorr idt*, sig
factor idt* [aweight=gewicht], pcf blanks(.4)
alpha idt*, item detail

*Create index variable
egen idt = rowmean(idt*)
tab idt, mis

*Subindizes
egen idtshort = rowmean(idtwork idtfinance idtfamily)
egen idtecon = rowmean(idtwork idtfinance)

*Objective change in income due to corona
tab1 erw8b erw16, mis
gen double incloss = erw16==1 
*replace incloss=0 if(erw2==4 |erw2==6) //Beamte and MFA have no loss
*replace incloss=0 if erw2==5
replace incloss=1 if(erw2==5 & (erw19==3 | erw19==4))
*replace incloss=0 if(erw1==8 | erw1==10) // Rentner and unemployed have no loss
tab incloss, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Political attitudes
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Left-Right-self positioning
tab inst4, mis  //too much missings, don't use this variable!
recast double inst4
recode inst4 (11 12 .= .), gen(leftright)
label var leftright "Left-Right-Self-Assess"
tab leftright, mis

gen double leftrightDK = inst4==11 if inst4~=.
gen double leftrightNR = inst4==12 if inst4~=.
gen double leftrightORIG = inst4
tab1 leftrightDK leftrightNR, mis

recode inst4 (0/3=1) (4/6=2) (7/10=3) (11/12=4), gen(leftrightcat)
label variable leftrightcat "Left-Right categorical"
label define lericat 1 "left" 2 "mid" 3 "right" 4 "DK and NR"
label value leftrightcat lericat
numlabel lericat, add
tab leftrightcat, mis

*Party preference
tab1 inst6*, mis
gen other = inst6_other~=".FILTER"
tab other, mis
replace inst6 = 7 if other==1
gen double partypref = inst6
label define inst6 7 "keine/andere Partei", modify
label value partypref inst6
tab partypref, mis
drop other


*Trust in institutions
tab1 inst1a, mis
rename inst1a trustbundesreg
rename inst1b trustbundestag
rename inst1c trustlandreg
rename inst1d trustparties
rename inst1e trusttelly
rename inst1f trustjournals
rename inst1g trustsocmed
rename inst1h trusthealthsys
rename inst1i trustpolice
rename inst1j trustscience

recast double trust*

factor trust* [aweight=gewicht], pcf blanks(.4)
rotate, oblique oblimin blanks(.4)  //different results than in the spring wave!!

*Test subdimensions for uni-dimensionality
factor trustbundes* trustland trustparties trusthealthsys trustpolice trustscience ///
   [aweight=gewicht] , pcf blanks(.4) //yep

factor trusttelly trustjournals trustsocmed ///
   [aweight=gewicht] , pcf blanks(.4)  //yep, but this doesn't make sense

*Reliability
alpha trustbundes* trustland trustparties trusthealthsys trustpolice trustscience, item detail
alpha trusttelly trustjournals trustsocmed, item detail  //social media problematic

*Generate index variables
egen truststate = rowmean(trustbundes* trustland trustparties trusthealthsys trustpolice trustscience)
egen trustmedia = rowmean(trusttelly trustjournals trustsocmed)
egen trustpress = rowmean(trusttelly trustjournals)
tab1 truststate trustmedia trustpress

gen doubtstate = 8-truststate
gen doubtmedia = 8-trustmedia
gen doubtpress = 8-trustpress
gen doubtsocmed = 8-trustsocmed


*How truthfully has the government informed?
tab inst3, mis
recast double inst3
gen doubtgovtruth = 6-inst3
tab doubtgovtruth, mis


*General trust
tab inst8, mis
recast double inst8
gen gentrust = inst8
tab gentrust, mis

*Communism cleavage, strong transfer state
tab umv4, mis
gen double protransfer = umv4
tab protransfer, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Covid risk group
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

*Trust in health system if infected
tab welf5, mis
recast double welf5
gen trusthsyscorona = 6-welf5
gen doubthsyscorona = welf5
tab1 trusthsyscorona doubthsyscorona, mis

*Risk group
tab ges4 , mis //problem: many refusals
gen float riskgroup01 = ges4 if(ges4~=9 & ges4~=.)
gen float riskgroup = ges4
gen float riskgroupmiss = ges4==9 if ges4~=.
tab1 riskgroup*, mis

*General health
tab ges1, mis
gen float health = 6-ges1 if ges1<6
tab health, mis

gen badhealth = 6-health
tab badhealth

*Contact with infected people
tab1 ges3*, mis
gen float contact = ges3
replace contact = 1 if (ges3_other~="")
replace contact = . if(ges3==. & ges3_other==".")
tab contact, mis 


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Sociodemographics and other
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Life satisfaction
tab zufr1, mis
gen double lsatisfac = zufr1
tab lsatisfac, mis

*Sex
tab stat1, mis
recast float stat1
recode stat1 (0=0) (1 2=1), gen(female)
label var female ""
tab female, mis

*Age
tab1 stat2*, mis
gen double age = 2020-stat2
tab age, mis

gen agedec = age/10

gen old = age>70
tab old, mis

*Eastern Germany
tab stat4 ost, mis //Berlin is grouped into Eastern, which we won't do
gen float east=ost
replace east=0 if stat4==3
tab stat4 east, mis
tab east

tab stat7, mis
recast float stat7
recode stat7 (1/3 5/7 9/12 15 17=0) (4 8 13 14 16 18 = 1) (.=.), gen(eastchild)
label var eastchild ""
tab stat7 eastchild, mis

*City vs. countryside
*apparently n.a. in nov wave?
gen float habitation = .

*Migration background
tab1 stat3*, mis nol
gen mig = 0 if (stat3a~=. & stat3b~=. & stat3c~=.)
replace mig = 1 if (stat3a==0 | stat3b==0 | stat3c==0)
replace mig=. if (stat3a==8 | stat3b==8 | stat3c==8)
tab mig, mis

*Children
tab stat12, mis
gen float children = stat12
tab children, mis

*Children at home
tab1 stat14, mis
gen float childrenathome = stat14>0 if stat14~=.
replace childrenathome = 0 if stat13==1
tab childrenathome, mis

*General education in years (nur only general education)
tab1 stat16*, mis
recast float stat16
recode stat16 (1=.) (2=7) (3=9) (4=10) (5=12) (6=13), gen(educgenyr)
tab1 stat17* educgenyr, mis

*General education categorical
gen float educgencat = stat16_gr3 
tab educgencat, mis
tab educgencat stat16, mis

*Vocational education in years
tab1 stat17 stat17_other, mis
recast float stat17
recode stat17 (1=1) (2=1) (3=3) (4=3) (5=0.5) (6=3) (7=3) (8=4) (9=4) (10=3) (11=0) (12=2), gen(educvocyr)
tab educvocyr , mis
tab stat18, mis
recast float stat18
recode stat18 (1=0) (2/5=2) (6=6) (7=1), gen(univyr)
tab stat17 univyr, mis
replace educvocyr = educvocyr+univyr if univyr<.
tab educvocyr, mis
drop univyr

*All education in years
gen educyr = educgenyr+educvocyr
tab educyr, mis

*Unemployed
tab1 erw1 erw15h, mis
gen float unemployed = erw1==8
replace unemployed = 1 if erw15h==1
tab unemployed, mis

*Partner
tab1 stat8 stat9, mis
gen float partner = (stat8==1 | stat8==2)
tab partner
replace partner=1 if stat9==1
tab partner, mis

*Weight
gen float persweight = gewicht



*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Variables appearing only in November wave
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Identification with Eastern Germany
tab ost_verb, mis
recast float ost_verb
recode ost_verb (4/5=4), gen(eastaffil)
label define eastaffil 1 "Deutscher" 2 "Ostdeutscher" 3 "Westdeutscher" 4 "unentsch./kein D"
label value eastaffil eastaffil
tab eastaffil, mis

gen fullossi = eastaffil==2 if eastaffil~=.
tab fullossi, mis

*Feeling of being lagged behind
tab zufr4, mis
gen float lagbehind = zufr4==1 if zufr4~=.
tab lagbehind, mis

*Conspiracy and other opinions towards Corona
tab1 mein1* mein2*, mis
foreach x of varlist mein1* mein2* {
    recast double `x'
}

factor mein1* mein2* [aweight=gewicht], pcf blanks(.4) mineigen(.9)
rotate, oblique oblimin blanks(.4) //fac1 = conspiracy, fac2 = trivialization

//dropping item 2a and generate two vars for the factors
gen mein2crec = 6-mein2c
tab1 mein2c mein2crec, mis
egen conspiracy = rowmean(mein1a-mein1c)
egen trivialization = rowmean(mein2b mein2crec mein2d)
tab1 conspiracy trivialization, mis


*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
*Recode infection rate variables
*XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
d kr*
sum kr_inz_rate kr_betr_rate kr_tod_md_kum
gen double kr_inz_rate10 = kr_inz_rate/10
gen double kr_tod_md_kum10 = kr_tod_md_kum/10

gen double kr_tod_rate = (kr_tod_md_kum*100000)/kr_population
gen double kr_tod_rate10 = (kr_tod_md_kum*10000)/kr_population
